/**
 * 
 */
package design_pattern.memento.whiteboxcheckpoints;

import java.util.Vector;

/**
 * @author linzq
 * 
 */
public class CareTaker {

  private Originator originator;

  private Vector mementos = new Vector();

  private int current;

  public CareTaker(Originator o) {
    this.originator = o;
    this.current = 0;
  }

  public int createMemento() {
    Memento mememto = originator.createMemento();
    mementos.add(mememto);
    return current++;
  }

  public void restoreMemento(int index) {
    Memento mememto = (Memento) mementos.elementAt(index);
    originator.restoreMemento(mememto);
  }

  public void removeMemento(int index) {
    mementos.remove(index);
  }

}
